<?php $this->headScript()->appendFile($this->baseUrl().'/js/fancybox/jquery.fancybox-1.3.4.js'); ?>
<?php $this->headLink()->appendStylesheet($this->baseUrl().'/js/fancybox/jquery.fancybox-1.3.4.css'); ?>
<style>
    h3{color:gray;}
</style>
<?php
    $this->title = "Detalhe do metaevento";
    $this->headTitle($this->title);
?>
<a style="float:right; position: relative;" class="linkBtn" href="<?php echo $this->Referrer();?>">Voltar</a>
<h2><?php echo $this->metaevento->metaevento; ?></h2>
<table>
    <tr><th style="width:100px;">Responsável:</th><td><?php echo $this->metaevento->responsavel; ?></td></tr>
    <tr><th>Status:</th><td><?php echo $this->metaevento->status; ?></td></tr>
</table>
<!-- Listagem de tarefas -->   
<div class="well" style="margin-top:20px;">
    <h3>Listagem de Tarefas</h3>
    <a style="margin-bottom:10px;" class="linkBtn" href="<?php echo $this->url(array('controller'=>'tarefas','action'=>'add-metaevento'));?>">Adicionar tarefa</a>
    <?php if($total_geral = count($this->tarefas)){ ?>
    <table  style="width:100%;">
        <tr>
            <th style="width:10px;">&nbsp;</th>
            <th>Tarefa</th>
            <th>Responsavel</th>
            <th>Prazo</th>
            <th>Status</th>
            <th style="width:60px;">&nbsp;</th>
        </tr>
    <?php
        $cont = 0;
        foreach($this->tarefas as $tarefa) :
            $cont++;
            if($cont % 2 == 0)
                echo '<tr class="even">';
            else
                echo '<tr class="odd">';
    ?>
            <td class="center" style="padding:5px 0px 0px 0px;"><?php 
                if($tarefa->dt_estimada < date("Y-m-d")){
                    $cor = 'red';
                    echo "<img width='15px' alt='Atrasado!' title='Atrasado!' src='".$this->baseUrl()."/images/status_vermelho.png'>";
                }
                else {
                    $cor = 'green';
                    echo "<img width='15px' alt='Ok!' title='Ok!' src='".$this->baseUrl()."/images/status_verde.png'>";
                }
            ?></td>
            <td class="texto"><?php echo $tarefa->tarefa;?></td>
            <td class="texto"><?php echo $tarefa->responsavel;?></td>
            <td class="texto" style="color:<?php echo $cor;?>;"><?php echo $this->formataData($tarefa['dt_estimada']);?></td>
            <td class="texto"><?php echo $tarefa->status;?></td>
            <td style="padding:0px 2px;">
                <a href="<?php echo $this->url(array('controller'=>'tarefas','action'=>'edit','tarefa_id'=>$tarefa->id));?>">
                <img alt="Editar"  title="Editar" src="<?php echo $this->baseUrl().'/images/edit.png'; ?>"></a>
                <a href="<?php echo $this->url(array('controller'=>'tarefas','action'=>'delete','tarefa_id'=>$tarefa->id));?>">
                <img alt="Apagar" title="Apagar" src="<?php echo $this->baseUrl().'/images/trash.png'; ?>"></a>
            </td>
    <?php
        echo "</tr>";
        endforeach;
    ?>
    </table>
    <?php
        if($total_geral==1){echo 'Apenas 1 tarefa encontrada!';} else {echo $total_geral.' tarefas encontradas.';}
    } else {echo "<br/><br/>Nenhuma tarefa encontrada!";} ?>
</div>
<!-- Fim da Listagem de tarefas -->   

<!-- Listagem de eventos -->   
<div class="well" style="margin-top:20px;">
    <h3>Listagem de Eventos</h3>
    <a  style="margin-bottom:10px;" class="linkBtn" href="<?php echo $this->url(array('controller'=>'metaevento','action'=>'add-evento'));?>">Vincular evento</a>
    <?php if($total = count($this->eventos)){ ?>
    <table  style="width:100%;">
        <tr>
            <th>Evento</th>
            <th>Início</th>
            <th style="width:60px;">&nbsp;</th>
        </tr>
    <?php
        $cont = 0;
        foreach($this->eventos as $evento) :
            $cont++;
            if($cont % 2 == 0)
                echo '<tr class="even">';
            else
                echo '<tr class="odd">';
    ?>
            <td class="texto"><?php echo $evento['fullname'] ;?></td>
            <td class="texto"><?php echo $this->formataData($evento['startdate']) ;?></td>
            <td style="padding:0px 2px;">

                <a class="participantes" href="<?php echo $this->url(array('controller'=>'metaevento','action'=>'ajax-lista-participantes','evento_id'=>$evento['id']));?>" style="padding-right:10px;">
                <img width="24px" alt="Participantes" title="Participantes" src="<?php echo $this->baseUrl().'/images/icon_users.png'; ?>">
                </a>

                <a href="<?php echo $this->url(array('controller'=>'metaevento','action'=>'delete-evento','evento_id'=>$evento['id']));?>">
                <img width="32px" alt="Apagar" title="Cortar vínculo!" src="<?php echo $this->baseUrl().'/images/icon_tesoura.png'; ?>">
                </a>

            </td>
    <?php
        echo "</tr>";
        endforeach;
    ?>
    </table>
    <?php
        if($total==1){echo 'Apenas 1 evento realizado!';} else {echo $total.' eventos realizados.';}
    } else {echo "<br/>Nenhum evento encontrado!";} ?>
</div>
<!-- Fim da Listagem de eventos -->   

<div class="well" style="margin-top:20px;">
    <h3  style="margin-bottom:10px;">Listagem de Tutores</h3>
    <?php if($total_geral = count($this->tutores)){ ?>
    <table  style="width:100%;">
        <tr>
            <th>Curso</th>
            <th>Tutor</th>
        </tr>
    <?php
        $cont = 0;
        foreach($this->tutores as $nome => $tutor) :
            $cont++;
            if($cont % 2 == 0)
                echo '<tr class="even">';
            else
                echo '<tr class="odd">';
    ?>
            <td class="texto"><?php echo $nome ;?></td>
            <td class="texto">
                <table><tr><th style="background-color: #ddd; padding:2px 5px;">Evento</th></tr>
                <?php $total = count($tutor);
                foreach($tutor as $linha) : ?>
                    <tr><td style="padding:2px;"><?php echo $linha['evento'] ;?></td></tr> 
                <?php endforeach;?>
                </table>
                <span style='color:gray;'>
                    <?php if($total==1){echo 'tutor em 1 evento.';} else {echo 'tutor em '.$total.' eventos.';} ?>
                </span>
            </td>
    <?php
        echo "</tr>";
        endforeach;
    ?>
    </table>
    <?php 
        if($total_geral==1){echo 'Apenas 1 tutor encontrado!';} else {echo $total_geral.' tutores encontrados.';}
    } else {echo "<br/>Nenhum tutor encontrado!";} ?>
</div>
<br/><br/>

<a class="linkBtn" href="<?php echo $this->url(array('controller'=>'metaevento','action'=>'index'));?>">Voltar</a>

<script type="text/javascript">
    
    $(".participantes").fancybox({
        'titlePosition'		: 'inside',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic'
    });
       
    function ajaxLink(link){
//        event.preventDefault();
        $('#fancybox-content').load(link);
    }
       
</script>